public class Maximum_subarray {
    public int maxSubArray(int[] nums) {
        int n=nums.length;
        if(n==0)return 0;
        int[] dp=new int[n];
        dp[0]=nums[0];
        int result=dp[0];
        for(int i=1;i<n;i++){
            dp[i]=Math.max(dp[i-1]+nums[i],nums[i]);
            if(result<dp[i]) result=dp[i];
        }
        return result;
    }
}
